package org.xx.armory.jpa;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.Date;

@Entity(name = "Book")
@Table(name = "BOOKS")
public class BookPO {
    private long id;
    private String title;
    private String author;
    private Date pubDate;
    private BigDecimal price;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "BOOK_ID")
    public long getId() {
        return this.id;
    }

    public void setId(
            long id
    ) {
        this.id = id;
    }

    @Column(name = "TITLE",
            unique = true)
    public String getTitle() {
        return this.title;
    }

    public void setTitle(
            String title
    ) {
        this.title = title;
    }

    @Column(name = "AUTHOR")
    public String getAuthor() {
        return this.author;
    }

    public void setAuthor(
            String author
    ) {
        this.author = author;
    }

    @Column(name = "PUB_DATE")
    public Date getPubDate() {
        return this.pubDate;
    }

    public void setPubDate(
            Date pubDate
    ) {
        this.pubDate = pubDate;
    }

    @Column(name = "PRICE",
            nullable = false,
            scale = 2)
    public BigDecimal getPrice() {
        return this.price;
    }

    public void setPrice(
            BigDecimal price
    ) {
        this.price = price;
    }

    @Override
    public final int hashCode() {
        return (int) this.id;
    }

    @Override
    public final boolean equals(
            Object obj
    ) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        if (!(obj instanceof BookPO)) {
            return false;
        }
        final BookPO other = (BookPO) obj;
        return other.id == this.id;
    }

    @Override
    public final String toString() {
        return "BookPO(" + this.id + ")@" + Integer.toHexString(System.identityHashCode(this));
    }
}
